<script>
export default {
  name: "WWorkOrderTuiHuiView",
  data() {
    return {
      rengong: 0,
      qita: 0,
      beizhu: "",
      accessoryList: {},
      add:{},
      ren:0,
      list: {},
      accessorjlList: {},
    }
  },
  methods: {
    onBack() {
      this.$router.go(-1);
    },
    handleStepperChange(){
      this.ren = 0
      this.accessoryList.forEach(item => {
        if(item.sl != 0) {
          this.ren = Number(this.ren) + Number(item.sl) * Number(item.jine)
          // console.log(this.ren)
          // console.log(item)
        }
      })

    },
    queding() {
      this.list.bjbz = this.beizhu
      this.add = this.accessoryList
      this.add.rengong = this.ren
      this.add.qita = this.qita
      // this.add.pid = this.$route.query.id
      console.log(this.add)
      this.axios.post(`http://localhost:9999/api-work-order-service/work-order/save`, this.list).then(res => {
        console.log(res)
        if (res.data.code == 1) {
          console.log(this.add)
          this.accessorjlList.name = this.add.map(obj => JSON.stringify(obj)).join(',');
          this.accessorjlList.pid = this.$route.query.id
          console.log(this.accessorjlList)
          this.axios.post(`http://localhost:9999/api-work-order-service/work-order/accessoryjlSave`, this.accessorjlList).then(res => {
            if (res.data.code == 1) {
              this.$toast.success("提交成功");
              this.$router.go(-1);
            }
          })
        } else {
          this.$toast.fail("提交失败");
        }
      })
    }
  },
  created() {
    this.axios.get(`http://localhost:9999/api-work-order-service/work-order/accessoryAll`).then(res => {
      this.accessoryList = res.data.data;
      // console.log(res)
      // console.log(this.list)
    })
    this.axios.get(`http://localhost:9999/api-work-order-service/work-order/accessoryjlAll`).then(res => {
      this.add = res.data.data;
      console.log(res)
      console.log(this.add)
    })
    // 获取参数
    this.id = this.$route.query.id
    // 查询
    this.axios.get(`http://localhost:9999/api-work-order-service/work-order/findById?id=` + this.id).then(res => {
      this.list = res.data.data;
      // console.log(res)
      console.log(this.list)
    })
  }
}
</script>

<template>
<div>
  <van-nav-bar
      title="报价"
      left-arrow
      @click-left="onBack"
      fixed
  />
  <h3>占位</h3>
  <div>
    <h4>配件选择</h4>
    <span>配件名称:</span><span>单价:</span><span>数量:</span>
    <div v-for = "accessory in accessoryList" :key="accessoryList.id">
      <van-button type = "default" :text = "accessory.name" />
      <van-button type = "default" :text = "accessory.jine + '元'" />
      <van-stepper v-model="accessory.sl" :min="0" :max="accessory.kucun" @change="handleStepperChange" />
    </div>
  </div>
  <div>
    <span>人工费合计:<van-cell-group>
        {{ren}}
      </van-cell-group>
    </span>
  </div>
  <div>
    <span>其他费用:
      <van-cell-group>
        <van-field v-model="qita" label="" />
      </van-cell-group>
    </span>
  </div>
  <div>
    <h4>备注:</h4>
    <van-cell-group>
      <van-field v-model="beizhu" label="" />
    </van-cell-group>
  </div>
  <van-button type="info" size="large" @click="queding">确定</van-button>
</div>
</template>

<style scoped>

</style>